home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / DIFFU.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  83 lines

  1. ############################################################################
  2. #
  3. #    File:     diffu.icn
  4. #
  5. #    Subject:  Program to show differences in files
  6. #
  7. #    Author:   Rich Morin
  8. #
  9. #    Date:     June 17, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  This program exercises the dif() procedure, making it act like the
  14. #  UNIX diff(1) file difference command.
  15. #
  16. #  Usage: diffu f1 f2
  17. #
  18. #    3d2
  19. #    < c
  20. #    7,8c6,7
  21. #    < g
  22. #    < h
  23. #    ---
  24. #    > i
  25. #    > j
  26. #
  27. ############################################################################
  28. #
  29. #  Links:  dif
  30. #
  31. ############################################################################
  32.  
  33. link dif
  34.  
  35. procedure main(arg)
  36.   local f1, f2, ldr, n1, p1, n2, p2, h
  37.  
  38.   if *arg ~= 2 then
  39.     zot("usage: diffu f1 f2")
  40.  
  41.   f1 := open(arg[1]) | zot("cannot open " || arg[1])
  42.   f2 := open(arg[2]) | zot("cannot open " || arg[2])
  43.  
  44.   every ldr := dif([f1,f2]) do {
  45.     n1 := *ldr[1].diffs; p1 := ldr[1].pos
  46.     n2 := *ldr[2].diffs; p2 := ldr[2].pos
  47.  
  48.     if n1 = 0 then {            # add lines
  49.       h := p1-1 || "a" || p2
  50.       if n2 > 1 then
  51.         h ||:= "," || (p2 + n2 - 1)
  52.       write(h)
  53.       every write("> " || !ldr[2].diffs)
  54.     }
  55.     else if n2 = 0 then {        # delete lines
  56.       h := p1
  57.       if n1 > 1 then
  58.         h ||:= "," || (p1 + n1 - 1)
  59.       h ||:= "d" || p2-1
  60.       write(h)
  61.       every write("< " || !ldr[1].diffs)
  62.     }
  63.     else {                # change lines
  64.       h := p1
  65.       if n1 > 1 then
  66.         h ||:= "," || (p1 + n1 - 1)
  67.       h ||:= "c" || p2
  68.       if n2 > 1 then
  69.         h ||:= "," || (p2 + n2 - 1)
  70.       write(h)
  71.       every write("< " || !ldr[1].diffs)
  72.       write("---")
  73.       every write("> " || !ldr[2].diffs)
  74.     }
  75.   }
  76. end
  77.  
  78.  
  79. procedure zot(msg)                # exit w/message
  80.   write(&errout, "diff: " || msg)
  81.   exit(1)
  82. end
  83.